//
//  ViewController.m
//  MKWebImage
//
//  Created by lily on 17/1/1.
//  Copyright © 2017年 lily. All rights reserved.
//

#import "ViewController2TVC.h"
#import "CustomCell.h"
#import "DB/DataPersist.h"

@interface ViewController2TVC ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *tbView;
@property (nonatomic, strong) NSMutableArray *datasource;
@end

@implementation ViewController2TVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
//    NSString *path = [[NSBundle mainBundle] pathForResource:@"imagelist" ofType:@"plist"];
//    [self.datasource addObjectsFromArray:[NSArray arrayWithContentsOfFile:path]];
//    [self.tbView reloadData];
    
    //读取数组值
    NSMutableArray *MACArray = [[DataPersist readValueNSMutableArray:@"homeindex"] mutableCopy];
    //NSLog(@"第一次读取的值MACArray value is:%@",MACArray);
    
    NSMutableArray *dataarr = [MACArray valueForKey:@"data"];
    NSLog(@"dataarr %@ ",dataarr);
    
    NSMutableArray *aceServicesarr = [dataarr valueForKey:@"aceServices"];
    NSLog(@"aceServicesarr %@ ",aceServicesarr);
//    NSString *item3 = [dataarr firstObject];
//    NSLog(@"item3  %@",item3);
    
    //声明一个空的数组，用于存放字典的value
//    NSMutableArray *mFirstArray = [NSMutableArray array];
//    for (NSString *item in dataarr) {
//        NSLog(@"item=%@",item);
//        
//        NSDictionary * mSecondDic = [[NSDictionary alloc]initWithObjectsAndKeys: item,@"picture", nil];
//        [mFirstArray addObject:mSecondDic];
//    }
    
    //NSLog(@"mFirstArray is %@",mFirstArray);
    self.datasource = aceServicesarr;
    [self.tbView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   return self.datasource.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 88;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *strCell = @"CustomCell";
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:strCell];
    if (!cell) {
        cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strCell];
    }
    [cell setModel:self.datasource[indexPath.row]];
    return cell;
}

- (UITableView *)tbView {
    if (!_tbView) {
        _tbView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height - 20) style:UITableViewStylePlain];
        _tbView.delegate = self;
        _tbView.dataSource = self;
        [self.view addSubview:_tbView];
    }
    return _tbView;
}

- (NSMutableArray *)datasource {
    if (!_datasource) {
        _datasource = [NSMutableArray arrayWithCapacity:0];
    }
    return _datasource;
}

@end
